<template>
	<li class="aui-list-item">
        <div class="aui-btn aui-btn-block" @click.stop="saveInfor" v-bind:class="{ 'aui-btn-danger' : getBillList?true:false }">
            确认
        </div>
    </li>
	
	
</template>

<script>
	import axios from "axios";
	// import api from "../../api";
	import {Popup, MessageBox} from 'mint-ui';
	import {Toast} from '../../utils/toast';
	import { mapState, mapGetters, mapMutations } from "vuex";
	export default {
		data(){
			return {
				ParentOrderNos:"",
				rids:'',
				orderNo:'',//礼品卡的订单号
				giftCard:'',//礼品卡的订单补开发票标志
				flag:true,//防止多次点击
			}
		},
      	props: {
//	      	orderNo: {
//		        type: String,
//	//		        default: () => {
//	//		          return false
//	//		        }
//		        required:true
//		    },
		    types: {
		        type: Boolean,
	//		        default: () => {
	//		          return false
	//		        }
		        required:true
		    },
	    },
	    computed: {
	    	getBillList() {
                return this.$store.state.hzh.getBillInfor;
            },
            getBillContent() {
                return this.$store.state.hzh.BillContent;
            },
            
	    },
		components:{
			// "my-header":MyHeader,
		},
		watch:{
			
		},
		methods: {
            //保存信息
	      	async saveInfor(){
	      		let getVal = this.$router.history.current.query.datas;
	      		this.ParentOrderNos =  this.$router.history.current.query.parentOrderNo;
	      		this.orderNo =  this.$router.history.current.query.orderNo;
	      		this.giftCard =  this.$router.history.current.query.giftCard;
	      		let abc = await this.$store.state.hzh.getBillInfor;
				console.log("999999",abc,this.$route.query.datas)
	      		if(getVal){
					   if(!this.getBillList){
//					  	MessageBox.alert('请选择发票抬头')
						  return
					  }
					  if(!this.flag)return

					  this.flag = false;
					if(this.giftCard){
						this.giftCardBills(abc)
					}else{
						this.openBills(abc);
					}
	      			
//	      			console.log("开票申请的跳转到订单页")
//	      			this.$router.push('order')
	      			return
	      		};
	      		if(this.getBillList.length == 0){
//    			 	MessageBox.alert('请选择发票抬头')
      			 	return
	      		}
				console.log("zhouxinsjhige111",this.getBillList,this.getBillContent)
				this.$store.dispatch('hzh/SaveBillBtn', "tures");
	      		this.$router.go(-1);
	      	},
	      	//开票申请的接口
	      	async openBills(abc){
		    	// await this.$store.dispatch('hzh/GetBillheads');
				// abc.forEach(items => {
				// 	this.rids = items.rid
				// })
				this.rids = abc;
		    	var sessionId = localStorage.getItem('sessionId');
//		    	console.log("content////////",this.SaveBillContent) 
	            var url = window.api.trade_host + "/orderElectronicInvoice/pubElectronicInvoice" +"?invoicesTitleId="+ this.rids+"&invoiceContext="+ this.getBillContent+"&parentOrderNo="+ this.ParentOrderNos+"&orderNo="+ this.$route.query.datas;
	            // console.log(url,"我贼强啊")
	            var config = {
	               url,
	               method: "put",
	               headers: {sessionId},
	            }
	            await axios(config).then((res) => {
	                console.log("hahahahahahahaha222", res)
	                if(res.data.returnCode === 1){

						Toast({
	                        message: '申请成功',
	                        duration: 2000,
	                        type:'success'
	                    });
						if(this.$route.query.orderStatus == null) {
		//              	console.log("nishizhengaya")
							window.history.go(-1);
						} else {
		//					console.log("tashizhengaya")
							this.$router.push({
								path: 'order',
								query: {
									orderStatus: this.$route.query.orderStatus
								}
							})
						}
//						this.BillDetails = res.data.data;
//						this.$store.dispatch('hzh/SaveClickAddress', res.data.data);
						this.flag = true;
	                }else if(res.data.returnCode === 0){
	                	MessageBox.alert(res.data.msg)
//	                	.confirm(res.data.errmsg).then(action => {
//		                   this.$router.push('/login');
//		                });
						this.flag = true;
	                }else if(res.data.returnCode === 2){
	                	MessageBox.alert(res.data.msg)
						this.flag = true;
					}
	            
	            })
	      	},
			//礼品卡开票申请的接口
	      	async giftCardBills(abc){
		    	// await this.$store.dispatch('hzh/GetBillheads');
				// abc.forEach(items => {
				// 	this.rids = items.rid
				// })
				this.rids = abc;
		    	var sessionId = localStorage.getItem('sessionId');
//		    	console.log("content////////",this.SaveBillContent) 
	            var url = window.api.trade_host + "/orderElectronicInvoice/giftCardSupplyInvoice" +"?invoicesTitleId="+ this.rids+"&invoiceContext="+ this.getBillContent+"&orderNo="+ this.orderNo;
	            // console.log(url,"我贼强啊333333")
	            var config = {
	               url,
	               method: "put",
	               headers: {sessionId},
	            }
	            await axios(config).then((res) => {
	                console.log("hahahahahahahaha33333", res)
	                if(res.data.returnCode === 1){
	                	Toast({
	                        message: res.data.msg,
	                        duration: 2000,
	                        type:'success'
	                    });
						// console.log("开票申请的跳转到订单页")
						this.$router.go(-1);
	      				// this.$router.push('order')
//						this.BillDetails = res.data.data;
//						this.$store.dispatch('hzh/SaveClickAddress', res.data.data);
						this.flag = true;
						
	                }else if(res.data.returnCode === 0){
	                	MessageBox.alert(res.data.msg)
//	                	.confirm(res.data.errmsg).then(action => {
//		                   this.$router.push('/login');
//		                });
						this.flag = true;
	                }
	            
	            })
	      	}
		},
		mounted() {
			
		},
		beforeDestroy() {
			MessageBox.close(false);
		},
	}
	
</script>

<style>
</style>